#include <string.h>
#include "vr.h"
#include "vrProtoTypes.h"

#define VRML_ERROR_LINE_REPORT

//#define GENERATE_STANDARD_PROTOS
#ifndef GENERATE_STANDARD_PROTOS
	void init_std_protos();
#else
	void out_protos();
#endif

//#define PARSE_DEBUG

#define START_FIELD_NUM 5
#define ADD_FIELD_NUM 5
#define NODE_STACK_MAX 1000

class RouteParseList;
//--------------------------------------------------
// Class whose object contains all trees with root 
// having particular name (DEF "name" + USE "name") 
//--------------------------------------------------
	
class DEFParse{
public:
	char name[NAME_LEN];
	VRMFNode trees;
	unsigned int repository_size; // size of trees.values - needed for dynamic reallocation
	DEFParse(char* nm);
	void add_tree(VRNode* t);
	~DEFParse();
};

//--------------------------------------------------
// Class whose object contains all DEF's of some
// syntactic context
//--------------------------------------------------
class DEFFrameParse{
public:
	DEFParse** defs;
	int defs_num;
	int size;
	DEFFrameParse* prev; // pointer to including frame
	DEFFrameParse(DEFFrameParse* prv);
	~DEFFrameParse();
	int add(DEFParse* d);
	DEFParse* find(char* nm);

	RouteParseList* route_list;
};

//--------------------------------------------------
// Class whose object contains all syntactic contexts
//--------------------------------------------------
class DEFFrameStack{
public:
	DEFFrameParse* top;
	void push();
	void pop();
	DEFFrameStack();
	~DEFFrameStack();
};

//--------------------------------------------------
// Auxiliary node that takes care for "Inline"s
//--------------------------------------------------
class VRInline:public VRNode{
public:
	int path_found;
	char fname[256];
	VRInline();
	int get_file_path(VRMFString* possible_paths);
};


//--------------------------------------------------
// Extracts name from path
//--------------------------------------------------
void extract_path(char* fname,char* where_to_put);

//--------------------------------------------------
// Different initialization functions
//--------------------------------------------------
void init_atomic_types();
void clean_type_table();

// Adds new type to global type table
int add_type(VRParseType* tp);
int get_vector_length(int);

// finds a type in "all_types"
VRParseType* lookup_type(char* name); 
VRParseField* lookup_field(char* name);

// Function that dispatches VRNode creation according
// to the node's type 
VRNode* create_struct(VRParseType* type);


int treat_file(char *file_path_in,char* tmp_dir,char* fole_path_out);
int yyerror(char * s);
int format_uncompatability_report(char *s);

extern int type_num;
extern VRParseType** all_types;
extern int ExpectedFloatNumbersInValue; // needed for parser for lexical context choosing
extern VRParseType* current_proto;
extern VRParseField* current_field;
extern VRParseType* node_stack[NODE_STACK_MAX];
extern VRNode* vr_struct_stack[NODE_STACK_MAX];
extern int node_stack_ptr;
extern int vr_struct_stack_ptr;
extern DEFFrameStack def_stack;

#ifdef GENERATE_STANDARD_PROTOS
extern char exec_dir[];
#endif

#ifdef PARSE_DEBUG
extern int cur_line;
#define rdc(str) if( PARSE_DEBUG - 0   <=  cur_line ) printf("reducing %s\n",str)
#define usn(str) if( PARSE_DEBUG - 0   <=  cur_line ) printf("using %s\n",str)
#else
#define rdc(str) 
#define usn(str) 
#endif
